package net.disy.cadenza.repository.selector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class TableCondition {
	private String tableName;
	private Set<String> columnNames;
	private Map<String, Set<String>> columnValuesMap;
	
	public TableCondition(String tableName, String columnName){
		this.tableName = tableName;
		this.columnNames = new HashSet<String>();
		this.columnNames.add(columnName);
		this.columnValuesMap = new HashMap<String, Set<String>>();
	}
	
	public void addColumn(String columnName){
		columnNames.add(columnName);
	}
	public void addColumnValue(String columnName, String value){
		Set<String> columnValues = columnValuesMap.get(columnName);
		if(columnValues == null){
			columnValues = new HashSet<String>();
			columnValuesMap.put(columnName, columnValues);
		}
		if(value.indexOf("\n") == -1)
			columnValues.add(value);
		else{
			StringTokenizer st = new StringTokenizer(value, "\n");
			while(st.hasMoreElements())
				columnValues.add(st.nextToken());
		}
	}

	public String getTableName() {
		return tableName;
	}

	public Set<String> getColumnNames() {
		return columnNames;
	}

	public Map<String, Set<String>> getColumnValuesMap() {
		return columnValuesMap;
	}
	
	
}
